package home.projects.misc;

import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Locale;

import javax.security.auth.callback.LanguageCallback;

public class DateTest {

   private static final String URL =
      "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=#FROM#%7C#TO#&q=";

   private static final String URL2 =
      "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair={0}%7C{1}&q=";
   
   public static void main(final String[] args) throws Exception {
      testPerf();
   }

   private static void testPerf() {
      Locale from = Locale.CANADA;
      Locale to = Locale.FRANCE;
      long time;
//      for(int i = 0; i < 10000; ++i) {
//         URL.replaceAll("#FROM#", from.toString()).replaceAll("#TO#", to.toString());
//      }
//      for(int i = 0; i < 10000; ++i) {
//         java.text.MessageFormat.format(URL2, from.toString(), to.toString());   
//      }
      time = System.currentTimeMillis();
      for(int i = 0; i < 10000; ++i) {
         java.text.MessageFormat.format(URL2, from.toString(), to.toString());   
      }
      System.out.println("Time for message format: " + (System.currentTimeMillis() - time));
      time = System.currentTimeMillis();
      for(int i = 0; i < 10000; ++i) {
         URL.replaceAll("#FROM#", from.toString()).replaceAll("#TO#", to.toString());
      }
      System.out.println("Time for replaceall: " + (System.currentTimeMillis() - time));
   }
   
   private static void testLoader() throws Exception {
      ClassLoader loader = ClassLoader.getSystemClassLoader();
      URL u1 = new URL("file:///E:/rnd/eclipse-workspace/AOP/bin/");
      System.out.println(u1);
      URLClassLoader ucl = URLClassLoader.newInstance(new URL[] { u1 });
      Class c = ucl.loadClass("home.projects.aop.components.SDFAspect");
      Method[] ms = c.getDeclaredMethods();
      for (Method m : ms) {
         System.out.println(m);
      }
   }

}

class MyLoader extends ClassLoader {

   @Override
   protected Class<?> findClass(String name) throws ClassNotFoundException {
      return super.findClass(name);
   }

   @Override
   protected synchronized Class<?> loadClass(String name, boolean resolve)
         throws ClassNotFoundException {
      return super.loadClass(name, resolve);
   }

   @Override
   public Class<?> loadClass(String name) throws ClassNotFoundException {
      return super.loadClass(name);
   }

}